package net.knightwatch.kwtools.customers;

import java.util.ArrayList;

import net.knightwatch.kwtools.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BuildingArrayAdapter extends ArrayAdapter<Building> {
	public static final String TAG = "BuildingArrayAdapter";
	int resource;
	String response;
	Context context;
	/**
	 * Default constructor for BuildingArrayAdapter
	 * @param context
	 * @param resource
	 * @param buildings
	 */
	public BuildingArrayAdapter(Context context, int resource, ArrayList<Building> buildings){
		super(context, resource, buildings);
		this.resource=resource;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		LinearLayout buildingView;
		// Get the Current building object
		Building building = getItem(position);
		
		//Inflate the view
		if(convertView == null){
			buildingView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi = (LayoutInflater)getContext().getSystemService(inflater);
			vi.inflate(resource, buildingView, true);
		}
		else
		{
			buildingView = (LinearLayout) convertView;
		}
			//Get the text boxes from the listitem.xml file
	        TextView buildingName =(TextView)buildingView.findViewById(R.id.txtBuildingName);
	        TextView buildingAddress =(TextView)buildingView.findViewById(R.id.txtBuildingAddress);
	        buildingName.setText(building.getName());
	        buildingAddress.setText(building.getAddress().getStreet()+ " " + building.getAddress().getCity() + " " + building.getAddress().getState() + " " + building.getAddress().getZipcode());
	        return buildingView;
		}
}

